package formulation;

import java.util.ArrayList;
import java.util.List;

import es.deusto.ingenieria.is.csp.formulation.Constraint;
import es.deusto.ingenieria.is.csp.formulation.Variable;

public class Alldiff extends Constraint<Integer> {

	public Alldiff(String name, List<Variable<Integer>> variables) {
		super(name, variables);
	}

	@Override
	public boolean isSatisfied(Variable<Integer> variable, Integer value) {
		List<Variable<Integer>> variables = new ArrayList<Variable<Integer>>();
		variables = getVariables();
		for (Variable<Integer> var : variables) {
			if (!var.equals(variable) && !(var.getName().contains("X") && var.getName().length() > 1) && var.hasValue() && var.getValue().equals(value)) {
				return false;
			}
		}
		return true;
	}

	@Override
	public String toString() {
		String nombres = "";
		for (Variable<Integer> var : getVariables()) {
			nombres += var.getName() + ", ";
		}
		nombres = (String) nombres.subSequence(0, (nombres.length()) - 2);
		return "Aldiff" + " (" + nombres + ")";
	}
}
